package com.example.wan1.adapter;

import android.graphics.drawable.Drawable;
import android.text.Html;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.wan1.R;
import com.example.wan1.model.CollectArticleBean;
import com.example.wan1.model.MixedEntity;
import com.example.wan1.widget.ZQImageViewRoundOval;

import java.util.List;

import androidx.annotation.NonNull;

/***
 * 创建时间：2020/7/26 13:39
 * 创建人：10850
 * 功能描述：我的收藏 适配器，包含文章和项目两个部分
 */
public class MixedAdapter extends BaseMultiItemQuickAdapter<MixedEntity, BaseViewHolder> {

    public MixedAdapter(List<MixedEntity> data) {
        super(data);
        addItemType(MixedEntity.ART, R.layout.article_item);
        addItemType(MixedEntity.PRO, R.layout.project_list_item);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, MixedEntity mixedEntity) {
        CollectArticleBean item = mixedEntity.getBean();
        switch (helper.getItemViewType()) {
            case MixedEntity.ART:
                //分类
                helper.setText(R.id.article_tv_category, item.getChapterName());
                //分享人
                helper.setText(R.id.article_tv_author, item.getAuthor());
                //时间+标题
                helper.setText(R.id.article_tv_time, item.getNiceDate());
                helper.setText(R.id.article_tv_title, Html.fromHtml(item.getTitle()).toString());
                //收藏
                helper.setImageResource(R.id.article_iv_collect, R.mipmap.heart_red);
                helper.addOnClickListener(R.id.article_iv_collect);
                break;
            case MixedEntity.PRO:
                //增加圆角
                ZQImageViewRoundOval iv = helper.getView(R.id.project_list_iv);
                iv.setType(ZQImageViewRoundOval.TYPE_ROUND);
                iv.setRoundRadius(16);
                Glide.with(mContext).load(item.getEnvelopePic()).into(iv);

                helper.setText(R.id.project_list_author, item.getAuthor())
                        .setText(R.id.project_list_title, item.getTitle())
                        .setText(R.id.project_list_desc, Html.fromHtml(item.getDesc()).toString())
                        .setText(R.id.project_list_time, item.getNiceDate());
                helper.setImageResource(R.id.project_list_collect, R.mipmap.heart_red);

                helper.setGone(R.id.project_list_chaptername, false);

                Drawable drawable = mContext.getResources().getDrawable(R.mipmap.user);
                drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                TextView view = helper.getView(R.id.project_list_author);
                view.setCompoundDrawables(drawable, null, null, null);

                helper.addOnClickListener(R.id.project_list_collect);
                break;
        }
    }
}
